package cn.smile.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 毛苏宇
 * User: me
 * Date: 2021/4/22
 * Time: 16:02
 * Description:
 */
@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(NoHandlerFoundException.class)
    public String noHandlerFoundException(NoHandlerFoundException e, HttpServletRequest request) {
        //得到请求方式，GET/POST
        String method = e.getHttpMethod();
        System.out.println(method);
        //错误信息：No handler found for GET /test/erroroo
        String message = e.getMessage();
        System.out.println(message);
        return "/404";
    }

}
